/**
 * 
 */
package com.yangtao.prototype.master.dao;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.yangtao.framework.constant.Option;
import com.yangtao.framework.hibernate.BaseDao;
import com.yangtao.prototype.master.entity.CommonTree;

/**
 * @author 杨涛
 * 
 */
@Repository
public class CommonTreeDAO extends BaseDao<CommonTree> {
	/**
	 * 从当前树节点加载树的下一级节点
	 * 
	 * @param code
	 *            树节点的代码
	 * @param type
	 *            树的类型
	 * @return 所有子树
	 */
	public List<Option> getSubTrees(String code, String type) {
		List<Option> options = new ArrayList<Option>();
		String sql = "from CommonTree ct where ct.treeCode='" + code
				+ "' and ct.treeType='" + type + "'";
		// CommonTree ct = new CommonTree();
		// ct.setTreeType(type);
		// ct.setTreeCode(code);
		// PropertySelector ps = new PropertySelector();
		// ps.add("subTrees");
		CommonTree ct = findUnique(sql);
		if (ct != null) {
			Option o = null;
			for (CommonTree tree : ct.getSubTree()) {
				o = new Option();
				o.setValue(tree.getTreeCode());
				o.setText(tree.getTreeName());
				options.add(o);
			}
		}
		return options;
	}
}
